/*8f92WYTvNvqLOa023aQCKVl44Hrces+mhsIXRN0Zhpe6JAbTw0iAHrZezi0kzN06*/
/*
 * @Author: xiahui 
 * @PageInfo: 列表态按钮状态控制 
 * @Date: 2019-01-15 13:41:29 
 * @Last Modified by: zhangmi
 * @Last Modified time: 2021-07-28 15:48:47
 */
import { BUTTONID, FIELDS, FSTATUSFLAG, VERSION, AREA } from '../../constance';

function buttonControl(props, checkArr) {
	if (!checkArr) {
		checkArr = props.table.getCheckedRows(AREA.listTableId);
	}
	if (!checkArr || checkArr.length == 0) {
		// 没有选行
		props.button.setDisabled({
			[BUTTONID.Delete]: true,
			[BUTTONID.Edit]: true,
			[BUTTONID.Copy]: true,
			[BUTTONID.ApproveInfo]: true,
			[BUTTONID.Commit]: true,
			[BUTTONID.UnCommit]: true,
			[BUTTONID.Validate]: true,
			[BUTTONID.UnValidate]: true,
			[BUTTONID.Freeze]: true,
			[BUTTONID.UnFreeze]: true,
			[BUTTONID.End]: true,
			[BUTTONID.UnEnd]: true,
			[BUTTONID.ModifyDelete]: true,
			[BUTTONID.ControlScope]: true,
			[BUTTONID.BatchControlScope]: true,
			[BUTTONID.PayPlan]: true,
			[BUTTONID.StructFile]: true,
			[BUTTONID.File]: true,
			[BUTTONID.ModifyHistory]: true,
			[BUTTONID.QueryAboutBusiness]: true,
			[BUTTONID.PayExecState]: false,
			[BUTTONID.Print]: true,
			[BUTTONID.Output]: true,
			[BUTTONID.PrintCountQuery]: true
		});
	} else if (checkArr.length == 1) {
		// 单行选中
		let fstatusflag = checkArr[0].data.values[FIELDS.fstatusflag].value; // 合同状态
		let version = checkArr[0].data.values[FIELDS.version].value; // 版本号

		deleteBtnControl(props, fstatusflag, version);
		commitBtnControl(props, fstatusflag);
		unCommitBtnControl(props, fstatusflag);
		ExecuteGroupControl(props, fstatusflag, version);

		props.button.setDisabled({
			[BUTTONID.ControlScope]: false,
			[BUTTONID.BatchControlScope]: false,
			[BUTTONID.PayPlan]: false,
			[BUTTONID.StructFile]: false,
			[BUTTONID.File]: false,
			[BUTTONID.ModifyHistory]: false,
			[BUTTONID.QueryAboutBusiness]: false,
			[BUTTONID.PayExecState]: false,
			[BUTTONID.Print]: false,
			[BUTTONID.Output]: false,
			[BUTTONID.PrintCountQuery]: false
		});
	} else {
		// 多行选中
		props.button.setDisabled({
			[BUTTONID.Delete]: false,
			[BUTTONID.Commit]: false,
			[BUTTONID.UnCommit]: false,
			[BUTTONID.Validate]: false,
			[BUTTONID.UnValidate]: false,
			[BUTTONID.Freeze]: false,
			[BUTTONID.UnFreeze]: false,
			[BUTTONID.End]: false,
			[BUTTONID.UnEnd]: false,
			[BUTTONID.ModifyDelete]: false,
			[BUTTONID.ControlScope]: false,
			[BUTTONID.BatchControlScope]: false,
			[BUTTONID.PayPlan]: false,
			[BUTTONID.StructFile]: false,
			[BUTTONID.File]: false,
			[BUTTONID.ModifyHistory]: false,
			[BUTTONID.QueryAboutBusiness]: false,
			[BUTTONID.PayExecState]: false,
			[BUTTONID.Print]: false,
			[BUTTONID.Output]: false,
			[BUTTONID.PrintCountQuery]: false
		});
	}
}

/**
 * 删除按钮状态控制
 */
function deleteBtnControl(props, fstatusflag, version) {
	let status = fstatusflag == FSTATUSFLAG.free && parseInt(version) == VERSION.v1;
	props.button.setDisabled({ [BUTTONID.Delete]: !status });
}

/**
 * 提交按钮状态控制
 */
function commitBtnControl(props, fstatusflag) {
	let status = fstatusflag == FSTATUSFLAG.free;
	props.button.setDisabled({ [BUTTONID.Commit]: !status });
}

/**
 * 收回按钮状态控制
 */
function unCommitBtnControl(props, fstatusflag) {
	let status = fstatusflag == FSTATUSFLAG.approving || fstatusflag == FSTATUSFLAG.approve;
	props.button.setDisabled({ [BUTTONID.UnCommit]: !status });
}

/**
 * 执行按钮组状态控制
 */
function ExecuteGroupControl(props, fstatusflag, version) {
	let status = fstatusflag == FSTATUSFLAG.approve;
	props.button.setDisabled({ [BUTTONID.Validate]: !status }); // 生效

	status = fstatusflag == FSTATUSFLAG.validate;
	props.button.setDisabled({
		[BUTTONID.UnValidate]: !status, // 取消生效
		[BUTTONID.Freeze]: !status, // 冻结
		[BUTTONID.End]: !status // 终止
	});

	status = fstatusflag == FSTATUSFLAG.frozen;
	props.button.setDisabled({ [BUTTONID.UnFreeze]: !status }); // 解冻

	status = fstatusflag == FSTATUSFLAG.terminate;
	props.button.setDisabled({ [BUTTONID.UnEnd]: !status }); // 取消终止

	status = fstatusflag == FSTATUSFLAG.free && parseInt(version) != VERSION.v1;
	props.button.setDisabled({ [BUTTONID.ModifyDelete]: !status }); // 变更删除
}

export { buttonControl };

/*8f92WYTvNvqLOa023aQCKVl44Hrces+mhsIXRN0Zhpe6JAbTw0iAHrZezi0kzN06*/